<template>
	<view class="company-info">
		<u-sticky>
			<view class="sticky">
				<view class="base-info">
					<view class="company-name">{{companyInfo.customerName}}</view>
					<view>统一社会信用代码：{{companyInfo.socialCreditCode}}</view>
					<view class="u-flex u-row-between">
						<view>法人：{{companyInfo.legalRepresentative}}</view>
						<view>成立日期：{{companyInfo.establishmentDate?companyInfo.establishmentDate.split(' ')[0]:''}}
						</view>
					</view>
				</view>
				<u-tabs ref="tabs" :list="list" active-color="#2979ff" inactive-color="#606266" font-size="30"
					:current="current" @change="change"></u-tabs>
			</view>
		</u-sticky>
		<u-gap height="20" bg-color="#f0f2f6"></u-gap>
		<view v-if="companyId">
			<!-- 基本信息 -->
			<customer-base v-if="list[current].name=='基础信息' && showChild" :customerId="companyId"></customer-base>
			<!-- 资产信息 -->
			<asset-infomation v-if="list[current].name=='资产信息' && showChild" :customerId="companyId"></asset-infomation>
			<!-- 财务信息 -->
			<finance v-if="list[current].name=='财务信息' && showChild" :customerId="companyId"></finance>
			<!-- 经营信息 -->
			<operation v-if="list[current].name=='经营信息' && showChild" :customerId="companyId"></operation>
			<!--实际控制人信息-->
			<actual-controller v-if="list[current].name=='实际控制人' && showChild"
				:customerId="companyId"></actual-controller>
			<!--征信及负债-->
			<credit-debt v-if="list[current].name=='征信及负债' && showChild" :customerId="companyId"></credit-debt>
			<!--其他辅助决策-->
			<others v-if="list[current].name=='其他辅助决策' && showChild" :customerId="companyId"></others>
		</view>
	</view>
</template>

<script>
	import config from '@/common/js/config.js';
	//企业基本信息
	import customerBase from './baseInfo/components/customerBase.vue';
	//资产信息
	import assetInfomation from './assetInformation/components/assetInfomation.vue';
	//财务信息
	import finance from './financeInfo/components/finance.vue';
	//财务信息
	import operation from './operationInformation/components/operation.vue';
	//企业实际控制人
	import actualController from './actualController/components/actualController.vue';
	//征信及负债
	import creditDebt from './creditDebt/components/creditDebt.vue';
	// 其他辅助信息
	import others from './others/components/others.vue';
	import uploadFile from '@/common/ossutil/uploadFile.js'
	export default {
		components: {
			customerBase,
			assetInfomation,
			finance,
			operation,
			actualController,
			creditDebt,
			others
		},
		data() {
			return {
				list: [{
					name: '基础信息'
				}, {
					name: '资产信息'
				}, {
					name: '财务信息'
				}, {
					name: '经营信息'
				}, {
					name: '实际控制人'
				}, {
					name: '征信及负债'
				}, {
					name: '其他辅助决策'
				}],
				current: 0,
				companyId: null,
				companyInfo: {
					customerName: "",
					socialCreditCode: "",
					legalRepresentative: "",
					establishmentDate: "",
				},
				showChild: true,
				userInfo: null
			}
		},
		onShow() {
			if (uni.getStorageSync("refreshPage")) {
				let tempTitle = this.list[this.current].name
				this.list[this.current].name = ''
				this.$nextTick(() => {
					this.list[this.current].name = tempTitle
				});
				uni.removeStorageSync('refreshPage')
			}
		},
		onLoad(options) {
			const userProvider = uni.getStorageSync(config.Global.cache + '_UserProvider');;
			if (userProvider) {
				this.userInfo = userProvider
			}
			if (options.id) {
				this.companyId = options.id
				this.init()
			}
		},
		methods: {
			/* 初始化请求 */
			init() {
				this.$helper.ajax({
					url: "/api/Jiushi/Customerbase/" + this.companyId,
					method: "GET",
					contentType: "application/json",
					success: res => {
						this.companyInfo = res.data.data
						if (this.companyInfo.IsCreditI || this.userInfo.roleName.indexOf('管理员') > -1) {
							uni.setStorage({
								key: config.Global.cache + '_ShowCompanyButton',
								data: true
							});
						} else {
							uni.setStorage({
								key: config.Global.cache + '_ShowCompanyButton',
								data: false
							});
						}
					}
				});
			},
			change(index) {
				this.current = index;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.company-info {
		.base-info {
			background-color: #3281ff;
			padding: 0 24rpx;
			height: 160rpx;
			color: #fff;
			font-size: 28rpx;

			.company-name {
				font-size: 32rpx;
				font-weight: 600;
			}
		}
	}

	.content {
		padding: 60upx 40upx;
		font-size: 28upx;
		line-height: 48upx;
	}
</style>